#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N=4e5+5;
ll a[N];
int T;
int n=0;
unordered_map <ll,bool> mp;
int main(){
	freopen("kte.in","r",stdin);
	freopen("kte.out","w",stdout);
	ios::sync_with_stdio(0);
	cin.tie(0),cout.tie(0);
	int x;
cin>>T;
while(T--){
	cin>>x;
	if(mp[x]==1){
		mp[x]=0;
		for(int i=1;i<=n;i++){
			if(a[i]==x){
				for(int j=i+1;j<=n;j++){
					a[j-1]=a[j];
				}
				n--;
				break;
			}
		}
	}
	else{
		mp[x]=1;
		if(x>a[n]) a[++n]=x;
		else{
			for(int i=1;i<=n;i++){
				if(a[i]>x){
					for(int j=n;j>=i;j--) a[j+1]=a[j];
					a[i]=x;n++;
					break;
				}
			}
		}
	}
	ll L=0,R=-1,ans=0,las=0;
		for(int i=1;i<n;i++){
			L+=a[i],R+=a[n-i+1];
			ans+=max(0ll,R-max(las+1,L)+1);
			las=R;
		}
		cout<<ans<<'\n';
}
	return 0;
}

